import { message } from "antd";
import axios, { AxiosRequestHeaders } from "axios";



const tradeRequest = axios.create({
  baseURL:'/app-dev',
  timeout:6000
})

// 请求拦截器
tradeRequest.interceptors.request.use((config)=>{
  if(localStorage.getItem('token')){
    (config.headers as AxiosRequestHeaders).token = (localStorage.getItem('token') as string)
    return config
  }else{
    window.location.href = '/login' // 没有token去登录
  }
})
// 响应拦截器
tradeRequest.interceptors.response.use(({data})=>{
  if(data.code === 200) return data.data
  message.error(data.message)
  return Promise.reject('错误')
})

export default tradeRequest
